<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>菜单列表</title>
    <th:block th:include="~{common/common::commonHead}"/>
</head>
<body>
<div class="page-body">
    <div class="panel panel-primary shiny">
        <div class="panel-heading bg-blue">
            菜单列表
        </div>
        <div class="widget-body grid-table">
            <div class="toolbar">
                <div class="fl-left">
                    <button data-menu-id="100101" data-click="add('system/menuAdd.html','menuList', '添加一级菜单')" class="btn btn-blue shiny">添加一级菜单</button>
                    <button data-menu-id="100102" data-click="addSubMenu()" class="btn btn-info shiny">添加子菜单</button>
                    <button data-menu-id="100103" data-click="del('menuList','system/batchDelMenu','pid')" class="btn btn-danger shiny">批量刪除</button>
                </div>
                <div class="toolbar-right">
                    <div class="fl-right">
                        <div class="btn-group" role="group">
                            <button data-click="toggleFilter()" class="btn btn-default text-center">
                                <i class="fa fa-filter fa-fw"></i>
                            </button>
                            <button data-click="refresh('menuList')" class="btn btn-default">
                                <i class="fa fa-refresh fa-fw"></i>
                            </button>
                            <button data-click="download('menuList')" class="btn btn-default">
                                <i class="fa fa-download fa-fw"></i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            <div id="menuList"></div>
            <form class="filter search-content form-horizontal" role="form">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label"> 菜单编号 </label>
                        <div class="col-xs-8">
                            <div class="iconic-input right">
                                <input name="menuId" type="text" class="form-control spinner"
                                       placeholder="6位数字">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label"> 菜单名称 </label>
                        <div class="col-xs-8">
                            <div class="iconic-input right">
                                <input name="menuName" type="text" class="form-control spinner"
                                       placeholder="菜单名称">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label"> 上级菜单 </label>
                        <div class="col-xs-8">
                            <select name="parentId" class="form-control spinner"
                                    data-url="system/listMenu" data-value-field="menuId"
                                    data-text-field="menuName" data-value="-1">
                                <option value="-1">全部</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label"> 菜单级别 </label>
                        <div class="col-xs-8">
                            <select name="menuLevel" class="form-control spinner">
                                <option value="-1">全部</option>
                                <option value="1">一级</option>
                                <option value="2">二级</option>
                                <option value="3">三级</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label"> 菜单状态 </label>
                        <div class="col-xs-8">
                            <select name="menuStatus" class="form-control spinner">
                                <option value="-1">全部</option>
                                <option value="0">隐藏</option>
                                <option value="1">显示</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-xs-12">
                    <button type="button" data-click="hideFilter()" class="btn btn-default pull-right">取消</button>
                    <button type="button" data-click="submitFilter('menuList')" class="btn btn-blue pull-right">确定</button>
                </div>
            </form>
        </div>
    </div>

</div>
</body>
</html>
<script>
    $(function () {
        $("#menuList").gridTable({
            url: "system/pageMenu",
            columns: [
                {title: "菜单编号", field: "menuId"},
                {title: "菜单名称", field: "menuName"},
                {title: "菜单图标", field: "menuIcon"},
                {title: "菜单链接", field: "menuLink"},
                {title: "父级菜单", field: "parentId"},
                {title: "菜单级别", field: "menuLevel"},
                {title: "菜单状态", field: "menuStatusStr"},
                {title: "菜单排序", field: "menuSort"},
                {title: "创建时间", field: "createTime"},
                {title: "更新时间", field: "updateTime"}
            ],
            idField: "id",
            infoUrl: "system/menuInfo.html",
            editUrl: "system/menuEdit.html",
            delUrl: "system/delMenu"
        });
    });

    function addSubMenu() {
        var gridTable = $$selection.get("gridTable", "menuList");
        var selectedRows = gridTable.getSelectedRows();
        if (selectedRows.length !== 1) {
            $.error("请选择 <span class='text-danger'>一个</span> 父级菜单");
            return;
        }
        var menuId = selectedRows[0].getData().menuId;

        $.openIframeDialog({
            title: "新增子菜单",
            url: "system/menuAdd.html",
            param: {parentId: menuId},
            afterSubmit: function () {
                var gridTable = $$selection.get("gridTable", "menuList");
                gridTable.reloadData();
                $.success("添加成功");
            }
        });
    }
</script>